/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2021并保留所有权利。
 * Copyright 2021, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.moshi.test.learn.ifelse.test.meiju;

import java.util.Objects;

/**
 * 活动策略工厂
 */
public class ActivityStrategyFactory {
    //静态内部类
    public static class Holder {
        public static ActivityStrategyFactory instance = new ActivityStrategyFactory();
    }

    //提供公有方法对外进行访问
    public static ActivityStrategyFactory getInstance() {
        return Holder.instance;
    }

    //私有构造函数,提供单例工厂
    private ActivityStrategyFactory() {
    }

    //根据类型，通过反射获取具体活动策略对象
    public ActivityStrategy getActivityStrategy(String type) {
        try {
            Objects.requireNonNull(type);//非空判断
            return (ActivityStrategy) Class.forName(type).newInstance();
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}
